package lab03.test03;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        //写文件
        String path="D:\\test.txt";
        String value="Beijing 欢迎你!";
        FileOutputStream fileOutputStream=null;
        try {
            fileOutputStream=new FileOutputStream(path);
            try {
                fileOutputStream.write(value.getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally{
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //读文件
        try {
            FileInputStream fileInputStream=new FileInputStream(path);
            int tmp;
            try {
                while((tmp=fileInputStream.read())!=-1){
                    System.out.println((char)tmp);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally{
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
